h<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>My JSP 'packformStyleList.jsp' starting page</title>
		<script type="text/javascript">
	function addPackStyle() {
		//if (confirm("您还没有为该品牌制作随箱单，是否现在去制作？")) {
			window.self.location = "${ctx}/v2/packformStyle/add/" + $("#customerId").val();
		//}
	}
	function ajaxCustomerCodePackformStyle(flg) {
		if(flg){
			
		}else{
			flg="ajaxCustomerCodePackformStyle";
		}
		var tempString = "";
		var tempIndex = 1;
		$.ajax({
					type : 'post',
					url : '${ctx}/v2/packformStyle/'+flg,
					data : 'customerCode=' + $("#customerId").val(),
					dataType : 'json',
					success : function(data) {
						if (data.status == "1") {
							tempString = "<div class=\"row\">";
							$.each(
											data.content,
											function(i) {
												tempString = tempString
														+ "<div class=\"col-md-6\">"
														+ "<div id=\"ss_"+data.content[i].id+"\">"
														+ data.content[i].styleContent
														+ "</div>"
														+ "<h5>随箱单名称："
														+ data.content[i].styleName
														+ "</h5><p>"
														+ "<a class=\"btn btn-info\" href=\"${ctx}/v2/packformStyle/updatePackStyle/"+data.content[i].id+"\">修改</a>"
														+ "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
														+ "<a id=\"view_"
														+ data.content[i].id
														+ "\" class=\"btn\"  role=\"button\" data-toggle=\"modal\"  href=\"#stylePreview\" onclick=\"viewStyle('"
														+ data.content[i].id
														+ "');\" >样式预览</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"javascript:DisplayPreview("
														+ data.content[i].id
														+ ")\"  class=\"btn\">打印预览</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"javascript:DeletepackStyle("
														+ data.content[i].id
														+ ")\"  class=\"btn btn-danger\">删除</a></p></div>";
												tempIndex++;
												if (tempIndex % 2 == 0) {
													tempString += "<br/>";
												}
											});
							tempString += "</div>";
							$("#packStyleViewId").html(tempString);
						} else if (data.status == "-1") {
							//addPackStyle(data.content);
							tempString = "<h4>您还没有为该品牌制作随箱单!!!</h4>";
							$("#packStyleViewId").html(tempString);
						}
					},
					error : function() {

					}
				});
	}
	function viewStyle(id) {
		$("#viewStyleBody").html(
				"<div style=\"width:1000\">" + $("#ss_" + id).html() + "</div>");
	}
	//打印预览
	function DisplayPreview(id) {
		LODOP = getLodop(document.getElementById('LODOP'), document
				.getElementById('LODOP_EM'));
		LODOP.ADD_PRINT_BARCODE(200, 250, 300, 50, "128B", "PD123456789012");
		LODOP.ADD_PRINT_BARCODE(10, 850, 200, 35, "128B", "PD123456789012");
		var strCenterStyle = "<style/>table {width:100%}</style>";
		LODOP.ADD_PRINT_HTM(90, 0, "100%", "100%", strCenterStyle
				+ $("#ss_" + id).html());
		//LODOP.SET_PRINT_STYLEA(2,"AngleOfPageInside",90);
		LODOP.SET_SHOW_MODE("BKIMG_PRINT", 1);
		LODOP.PREVIEW();
	};

	function ajaxCustomerIdBrands() {
		var tempString = "";
		$("#controlsBrandId").html(tempString);
		$
				.ajax({
					type : 'post',
					url : '${ctx}/v2/packformStyle/ajaxCustomerIdBrands',
					data : 'customerId=' + $("#customerId").val(),
					dataType : 'json',
					success : function(data) {
						if (data.status == "1") {
							tempString += "<select id=\"brandId\" name=\"brandName\" onchange=\"ajaxBrandIDpackStyle()\">";
							$
									.each(
											data.content,
											function(i) {
												tempString += "<option value="+data.content[i].id+">"
														+ data.content[i].brandName
														+ "</option>";
											});
							tempString += "</select>";
							$("#controlsBrandId").html(tempString);
						} else if (data.status == "0") {
							alert("加载出错！");
						} else if (data.status == "-1") {
							alert("您还没有为这个商家增加品牌！");
						}
						ajaxBrandIDpackStyle();

					},
					error : function() {

					}
				});
	}
	function DeletepackStyle(id) {
		if (confirm("是否确认删除！")) {
			//window.location.href = "${ctx}/v2/packformStyle/DeletepackStyle/"
			//		+ id;
			ajaxCustomerCodePackformStyle("deletepackStyleNew/" + id);
		}
	}
</script>
	</head>

	<body>
	<section class="content">
	<div class="row">
			<div class="col-md-12">
			<div class="box box-solid box-primary">
			<div class="box-header">
					<i class="fa fa-search"></i>
					<h3 class="box-title">搜索栏</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">
		<c:if test="${not empty message}">
			<div id="message" class="alert alert-success">
				<button data-dismiss="alert" class="close">
					×
				</button>
				${message}
			</div>
		</c:if>
		<div class="form-group row">
		<div class="col-sm-3">
		<div class="input-group col-sm-12">
			<label for="pmsprinters_corpLevel" class="input-group-text">
				商家名称:
			</label>
			<div class="controls">
				<select id="customerId" name="customerName" class="form-control"
					onchange="ajaxCustomerCodePackformStyle()">
					<c:forEach items="${customers}" var="customer">
						<option value="${customer.customerCode}"
							<c:if test="${customer.id eq brand.customers.id}">selected="selected"</c:if>>
							${customer.customerName}
						</option>
					</c:forEach>
				</select>
			</div>
			</div>
			</div>
		</div>
		<div class="form-group row">
			<div class="col-sm-6">
				<input id="submit_addbox" class="btn btn-primary" type="button" onclick="addPackStyle()" value="增加随箱单" />
			</div>
		</div>
		<div  id="packStyleViewId">
		</div>
		
		<script type="text/javascript">
				ajaxCustomerCodePackformStyle();
       </script>
       
       
		<div style="display: none; " class="modal fade"
			tabindex="-1" role="dialog" aria-hidden="true" id="stylePreview">
			<div class="modal-dialog" style="width: 60%">
			<div class="modal-content">
			<div class="modal-header bg-gray">
				<button type="button" class="close" data-dismiss="modal"
					aria-hidden="true">
					×
				</button>
				<h3 id="myModalLabel" class="modal-title">
					随箱单样式
				</h3>
			</div>
			<div class="modal-body" id="viewStyleBody">

			</div>
			<div class="modal-footer bg-gray">
				<button class="btn" data-dismiss="modal" aria-hidden="true">
					Close
				</button>
			</div>
		</div>	
		</div>
		</div>
		</div>
		</div>
		</div>
		</div>
		</section>
	</body>
</html>
